using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;

namespace BUS
{
    public class tbHinhsanphamBUS
    {
        public static void Insert(tbHinhsanpham hsp)
        {
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            hspDAL.Insert(hsp);
        }
        public static void Update(tbHinhsanpham hsp)
        {
            tbHinhsanphamDAL hspDAl = new tbHinhsanphamDAL();
            hspDAl.Update(hsp);
        }
        public static void Delete(int iD)
        {
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            hspDAL.Delete(iD);
        }
        public static tbHinhsanphamCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            return hspDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbHinhsanphamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            return hspDAL.Get(cri.Criter, 0, 0, tbHinhsanphamColumn.Mahinh.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbHinhsanpham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbHinhsanphamColumn.Mahinh.ToString(), Condition.EQUAL, iD);
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            tbHinhsanphamCollection hspCollection = hspDAL.Get(cri.Criter, 0, 0, tbHinhsanphamColumn.Mahinh.ToString(), OrderDirection.ASC.ToString(), out total);
            if (hspCollection.Count > 0)
                return hspCollection[0];
            return null;
        }
        public static tbHinhsanphamCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            return hspDAL.Get(cri.Criter, 1, number,
            tbHinhsanphamColumn.Mahinh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbHinhsanphamCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbHinhsanphamDAL hspDAL = new tbHinhsanphamDAL();
            return hspDAL.Get(cri.Criter, 1, number,
            tbHinhsanphamColumn.Mahinh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
